package br.ufrj.neg.reuniao.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.ufrj.neg.bean.Idioma;
import br.ufrj.neg.constants.General;

import br.ufrj.neg.reuniao.bean.ReuniaoBean;
import br.ufrj.neg.reuniao.model.ParticipanteModel;
import br.ufrj.neg.reuniao.model.ReuniaoModel;


public class MostrarReuniaoEditAction extends HttpServlet {
		
	private static final long serialVersionUID = -3113158265371305805L;
	//private static Logger log = Logger.getLogger("rootLogger");
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		ParticipanteModel pm = new ParticipanteModel();
		Idioma idioma = (Idioma) request.getAttribute("idioma");
		try {
			
			/*
			 * Pega a sessao
			 */
			HttpSession session = request.getSession(false);
			
			String idReuniao = request.getParameter("idReuniao");
			
			ReuniaoModel rm = new ReuniaoModel();
			ReuniaoBean rb = new ReuniaoBean();
			synchronized(session){
				//session.removeAttribute("NegociacaoBean");
				rb = rm.getReuniao(Integer.parseInt(idReuniao));
				//rb = (ReuniaoBean)session.getAttribute("ReuniaoBean");
			}
			request.setAttribute("idReuniao", Integer.parseInt(idReuniao));		
			
			if (rb != null)
				request.setAttribute("participantes", pm.listaParticipanteporReuniao(rb.getId()));
			
			request.getRequestDispatcher(General.TEMPLATE_REUNIAO_PATH + "cadastraReuniao.vm").forward(request,response);
			
		} catch (Exception e) {
			System.out.println(e);
			request.getRequestDispatcher(General.TELA_ERRO_500).forward(request,
					response);
		}
	}	
}


